﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;
namespace DatabaseProvider
{
    public class SQLHelper
    {
        /// <summary>
        /// Chose sql
        /// </summary>
        public  struct SQLDriver{
            public static readonly int Oracle = 1;
            public static readonly int MSSQL = 2;
            public static readonly int MYSQL = 3;
        }

        /// <summary>
        /// Get/Set connection string to database
        /// </summary>
        public static string getConntionStringFromXML(string strFilePath)
        {
            string strReturn = "", strEncrypt="";
            XmlDocument xmlDoc = new XmlDocument();
            xmlDoc.Load(strFilePath);
            strEncrypt = GetXmlConfigValue(xmlDoc, "ConnectionEncrypt");
            if (strEncrypt.ToLower().Equals("yes"))
            {
                //Return an decrypt connection string
            }
            else {
                //Return connection string 
                strReturn = GetXmlConfigValue(xmlDoc, "ConnectionString"); 
            }
           return strReturn;
        }

        private static string GetXmlConfigValue(XmlDocument xmlDoc,string sNodeName)
        {
            string sNodeValue = "";
            XmlDocument xml_Document = xmlDoc;
            XmlNodeList xnlNodelist = null;
            XmlNode xnParent = null;
            XmlNode xnChild = null;

            try
            {
                //Find the node by Tagname which should be exactle same as in our XML Configuration file.
                xnlNodelist = xml_Document.GetElementsByTagName(sNodeName);
                //Point to parent node from the Node List(In our example Configuration is the Parent Node.
                xnParent = xnlNodelist.Item(0);
                //Point to Child node.
                xnChild = xnParent.ChildNodes[0];
                //Read the value from the child node.
                sNodeValue = xnChild.InnerText.ToString();
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return sNodeValue;

        }
    }
}
